package com.lnsystem.service;

import java.util.HashMap;
import java.util.List;

import org.joda.time.DateTime;
import org.joda.time.LocalDate;
import org.springframework.stereotype.Component;

import com.lnsystem.model.AnalyticsEvent;
import com.lnsystem.model.Stock;
import com.lnsystem.model.StockDailyData;
import com.lnsystem.service.impl.AnalyticsServiceImpl.PricePositionToPivots;

@Component
public interface AnalyticsService {

	// method for SMA crossover with greater than average volume.
	public List<Stock> getStocksWithSMACrossOvers(int period);

	public boolean isSMACrossOverForStock(Stock s);

	// method for detecting different SMAs convergence/at close proximity
	public List<Stock> getStocksWithConvergingSMA();

	public boolean isSMAConvergingForStock(Stock s);

	// method for detecting different SMAs cross above/below.

	/**
	 * Gets all stocks that have the lowerSMA is moving below higherSMA
	 * (Example: 10dma crossing above 50dma).
	 * 
	 * @param minStockPrice
	 *            - the min stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param maxStockPrice
	 *            - the max stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param minVolume
	 *            - the min volume to be used for scanning stocks to check for
	 *            pocket pivots
	 * @param lowerSMA
	 *            - the lowerSMA period - example 10 - for 10dma
	 * @param higherSMA
	 *            - the higherSMA period
	 * @param scanStartDate
	 *            - date from which to start scanning for SMA cross, default -
	 *            current date.
	 */
	public List<Stock> getStocksWithSMACrossingAbove(double minStockPrice,
			double maxStockPrice, double minVolume, int lowerSMA,
			int higherSMA, boolean currentMonthResultsOnly,
			LocalDate scanStartDate);

	/**
	 * Gets all stocks that have the lowerSMA is moving below higherSMA for a
	 * stock.. (Example: 10dma crossing below 50dma).
	 * 
	 * @param minStockPrice
	 *            - the min stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param maxStockPrice
	 *            - the max stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param minVolume
	 *            - the min volume to be used for scanning stocks to check for
	 *            pocket pivots
	 * @param lowerSMA
	 *            - the lowerSMA period - example 10 - for 10dma
	 * @param higherSMA
	 *            - the higherSMA period
	 * @param scanStartDate
	 *            - date from which to start scanning for SMA cross, default -
	 *            current date.
	 */
	public List<Stock> getStocksWithSMACrossingBelow(double minStockPrice,
			double maxStockPrice, double minVolume, int lowerSMA,
			int higherSMA, boolean currentMonthResultsOnly,
			LocalDate scanStartDate);

	/**
	 * Checks if the lowerSMA is moving below higherSMA for a stock.. (Example:
	 * 10dma crossing above 50dma).
	 * 
	 * @param s
	 *            - the stock
	 * @param lowerSMA
	 *            - the lowerSMA period - example 10 - for 10dma
	 * @param higherSMA
	 *            - the higherSMA period
	 * @param currentMonthResultsOnly
	 *            - show results only for current month
	 * @param scanStartDate
	 *            - date from which to start scanning for SMA cross, default -
	 *            current date.
	 */
	public boolean isSMACrossingAboveForStock(Stock s, int lowerSMA,
			int higherSMA, boolean currentMonthResultsOnly,
			LocalDate scanStartDate);

	// method to scan for pocket pivots
	/**
	 * Checks if the lowerSMA is moving below higherSMA for a stock.. (Example:
	 * 10dma crossing below 50dma).
	 * 
	 * @param s
	 *            - the stock
	 * @param lowerSMA
	 *            - the lowerSMA period - example 10 - for 10dma
	 * @param higherSMA
	 *            - the higherSMA period
	 * @param currentMonthResultsOnly
	 *            - show results only for current month
	 * @param scanStartDate
	 *            - date from which to start scanning for SMA cross, default -
	 *            current date.
	 */
	public boolean isSMACrossingBelowForStock(Stock s, int lowerSMA,
			int higherSMA, boolean currentMonthResultsOnly,
			LocalDate scanStartDate);

	// method to detect basing action
	public List<Stock> getBasingStocks(LocalDate date);

	public boolean isStockFormingBase(Stock s, LocalDate date);

	public boolean isStockFormingBase(String symbol, LocalDate date);

	// method to get price crossing SMA list
	public List<Stock> getStocksWithPriceCrossingSMA(int period);

	public boolean isPriceCrossingSMAForStock(Stock s, int period);

	// method to scan for pocket pivots
	/**
	 * Gets all the stocks showing pocket pivot recently
	 * 
	 * @param minStockPrice
	 *            - the min stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param maxStockPrice
	 *            - the max stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param minVolume
	 *            - the min volume to be used for scanning stocks to check for
	 *            pocket pivots
	 * @param smaPeriod
	 *            - sma10/50/200 against which price movement to be tracked.
	 * @param scanStartDate
	 *            - date from which to start scanning for pocket pivots, default
	 *            - current date.
	 * @param currentMonthResultsOnly
	 *            - if true, it scans for pocket pivots only for the current
	 *            month in relation to the parameter-scanStartDate
	 * @param basingStocksOnly
	 *            - if true, it scans for pocket pivots and also checks if the
	 *            stock is forming base
	 */
	List<Stock> getStocksWithMostRecentPocketPivots(double minStockPrice,
			double maxStockPrice, double minVolume, int smaPeriod,
			LocalDate scanStartDate, boolean currentMonthResultsOnly,
			boolean basingStocksOnly);
	/**
	 * Gets all the stocks showing pocket pivot today/scanstartdate date parameter
	 * 
	 * @param minStockPrice
	 *            - the min stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param maxStockPrice
	 *            - the max stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param minVolume
	 *            - the min volume to be used for scanning stocks to check for
	 *            pocket pivots
	 * @param smaPeriod
	 *            - sma10/50/200 against which price movement to be tracked.
	 * @param scanStartDate
	 *            - date from which to start scanning for pocket pivots, default
	 *            - current date.
	 * @param basingStocksOnly
	 *            - if true, it scans for pocket pivots and also checks if the
	 *            stock is forming base
	 */	
	List<Stock> getStocksShowingPocketPivotToday(double minStockPrice,
			double maxStockPrice, double minVolume, int smaPeriod,
			LocalDate scanStartDate,boolean basingStocksOnly);
	
	/**
	 * Gets all the stocks showing pocket pivot recently
	 * 
	 * @param s -  the stock to check for pocket pivots.
	 * 
	 * @param dailyDataList - the daily/weekly/monthly list. 
	 * 
	 * @param smaPeriod
	 *            - sma10/50/200 against which price movement to be tracked.
	 * @param scanStartDate
	 *            - date from which to start scanning for pocket pivots, default
	 *            - current date.
	 * @param i - index of current daily/weekly/monthly object in the list.         
	 */
	boolean isPocketPivotFound(Stock s, List<StockDailyData> dailyDataList,
			int i, int smaPeriod, LocalDate scanStartDate);

	
	/**
	 * Gets all the stocks showing pocket pivot recently
	 * 
	 * @param stockList the list of stocks to check for pocket pivots.
	 * @param smaPeriod
	 *            - sma10/50/200 against which price movement to be tracked.
	 * @param scanStartDate
	 *            - date from which to start scanning for pocket pivots, default
	 *            - current date.
	 * @param currentMonthResultsOnly
	 *            - if true, it scans for pocket pivots only for the current
	 *            month in relation to the parameter-scanStartDate
	 * @param basingStocksOnly
	 *            - if true, it scans for pocket pivots and also checks if the
	 *            stock is forming base
	 */
	List<Stock> getStocksWithMostRecentPocketPivots(List<Stock> stockList,
			int smaPeriod, LocalDate scanStartDate,
			boolean currentMonthResultsOnly, boolean basingStocksOnly);
	
	/**
	 * Gets the most recent pocket pivot for the Stock
	 * 
	 * @param s
	 *            - the stock symbol
	 * @param smaPeriod
	 *            - sma10/50/200 against which price movement to be tracked.
	 * @param currentMonthPivotsOnly
	 *            - if true, it scans for pocket pivots only for the current
	 *            month in relation to the parameter-scanStartDate
	 * @param scanStartDate
	 *            - date from which to start scanning for pocket pivots, default
	 *            - current date.
	 */
	StockDailyData getMostRecentPocketPivot(Stock s, int smaPeriod,
			boolean currentMonthResultsOnly, LocalDate scanStartDate);

	/**
	 * Gets all the pocket pivots for the Stock using all the available
	 * stockdaily data.
	 * 
	 * @param s
	 *            - the stock symbol
	 * @param smaPeriod
	 *            - sma10/50/200 against which price movement to be tracked.
	 */
	List<StockDailyData> getAllPocketPivots(Stock s, int smaPeriod);

	// there has to be a method that will scan for pocketpivots for a stock
	// between certain date range.

	/**
	 * Gets all the stocks forming base and lower SMA crossing above higher SMA
	 * 
	 * @param minStockPrice
	 *            - the min stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param maxStockPrice
	 *            - the max stock price to be used for scanning stocks to check
	 *            for pocket pivots
	 * @param minVolume
	 *            - the min volume to be used for scanning stocks to check for
	 *            pocket pivots
	 * @param lowerSMA
	 *            - the lowerSMA period - example 10 - for 10dma
	 * @param higherSMA
	 *            - the higherSMA period
	 * @param currentMonthResultsOnly
	 *            - if true, it scans for SMA cross only for the current month
	 *            in relation to the parameter-scanStartDate
	 * @param scanStartDate
	 *            - date from which to start scanning for pocket pivots, default
	 *            - current date.
	 */
	List<Stock> getStocksFormingBaseAndSMACrossingAbove(double minStockPrice,
			double maxStockPrice, double minVolume, int lowerSMA,
			int higherSMA, boolean currentMonthResultsOnly,
			LocalDate scanStartDate);

	/**
	 * Checks if a stock is forming base and lower SMA crossing above higher SMA
	 * 
	 * @symbol - the stock symbol
	 * @param lowerSMA
	 *            - the lowerSMA period - example 10 - for 10dma
	 * @param higherSMA
	 *            - the higherSMA period
	 * @param currentMonthResultsOnly
	 *            - if true, it scans for SMA cross only for the current month
	 *            in relation to the parameter-scanStartDate
	 * @param scanStartDate
	 *            - date from which to start scanning for pocket pivots, default
	 *            - current date.
	 */
	boolean isStockFormingBaseAndSMACrossingAbove(String symbol, int lowerSMA,
			int higherSMA, boolean currentMonthResultsOnly,
			LocalDate scanStartDate);

	/**
	 * Gets all the stocks with price advance of at least percentageAdvance
	 * 
	 * @param percentageAdvance - the percentance of advance to look for.. 
	 * @param maxStockPrice
	 *            - the max stock price to be used for scanning stocks
	 * @param minVolume
	 *            - the min volume to be used for scanning stocks
	 */
	
	List<Stock> getStocksWithPriceAdvance(double percentageAdvance,
			LocalDate from, LocalDate to, double minPrice, double maxPrice,
			double minVolume);

	/**
	 * Calculates pivot points based on the given type, stock and the given timeframe 
	 * 
	 * @param pivotType - Standard/Fibnocci/Demark pivot, default=fib. 
	 * @param s
	 *            - the stock
	 * @param timeFrame
	 *            - can be weekly,daily or intraday. For now it calculates only daily timeframe pivots.
	 */
	HashMap<String, Double> getPivotPoints(int pivotType, Stock s, int timeFrame);

	/**
	 * Calculates price positon to the pivots based on the given type, stock and the given timeframe 
	 * 
	 * @param pivotType - Standard/Fibnocci/Demark pivot, default=fib. 
	 * @param s
	 *            - the stock
	 * @param timeFrame
	 *            - can be weekly,daily or intraday. For now it calculates only daily timeframe pivots.
	 */
	PricePositionToPivots getPricePositionToPivots(Stock s, int pivotType, int timeFrame);

	void addAnalyticsEvent(Stock s, StockDailyData todaysData,
			String analyticsEventType);




}